﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<!-- 下拉框 -->
<link rel="stylesheet" href="static/ace/css/chosen.css" />
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>
<!-- 日期框 -->
<link rel="stylesheet" href="static/ace/css/datepicker.css" />
</head>
<body class="no-skin">

	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
						
						<!-- 检索  -->
						<form action="fruitUser/listJoin.do" method="post" name="goodsForm" id="goodsForm">
						<%-- <input type="hidden" name="classIds" id="classIds" value="${classIds}"/> --%>
						<table style="margin-top:5px;">
							<tr>
								<td>
									<div class="nav-search">
									<span class="input-icon">
										<input class="nav-search-input" id="name" type="text" name="name" value="${pd.name}" placeholder="这里输入负责人姓名" style="vertical-align:top;width: 190px;"/>
										<i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
									</div>
								</td>
								<td>
									<div class="nav-search">
									<span class="input-icon">
										<input class="nav-search-input" id="phone" type="text" name="phone" value="${pd.phone}" placeholder="这里输入负责人手机号" style="vertical-align:top;width: 190px;"/>
										<i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
									</div>
								</td>
								<%-- <c:if test="${QX.cha == 1 }"> --%>
								<td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="searchs();"  title="检索"><i id="nav-search-icon" class="ace-icon fa fa-search bigger-110 nav-search-icon blue"></i></a></td>
								<%-- </c:if> --%>
								<%-- <c:if test="${QX.toExcel == 1 }"><td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="toExcel();" title="导出到EXCEL"><i id="nav-search-icon" class="ace-icon fa fa-download bigger-110 nav-search-icon blue"></i></a></td></c:if> --%>
							</tr>
						</table>
						<!-- 检索  -->
					
						     <table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
							  <thead>
							  
								<tr>
									<th class="center" style="width:50px;">排序</th>
									<th class="center">ID</th>
									<th class="center">负责人姓名</th>
                                    <th class="center">负责人手机号</th>
									<th class="center">农作物类型</th>
									<th class="center">种植面积 (亩)</th>
                                    <th class="center">加盟类型</th>
                                    <th class="center">阅读状态</th>
									<th class="center">操作</th>
								</tr>
							</thead>
													
							<tbody id="goodlist">
								
							<!-- 开始循环 -->	
							<c:choose>
								<c:when test="${not empty joinList}">
									<%-- <c:if test="${QX.cha == 1 }"> --%>
									<c:forEach items="${joinList}" var="pl" varStatus="vs">
												
										<tr>
											<td class='center' style="width: 30px;">${vs.index+1}</td>
											<td class="center">${pl.id }</td>
											<td class="center">${pl.name }</td>
                                            <td class="center">${pl.phone }</td>
											<td class="center">${pl.crops_class }</td>
                                            <td class="center">${pl.acreage }</td>
                                            <td class="center"><c:if test="${pl.type=='01'}">经销商</c:if><c:if test="${pl.type=='02'}">农场主</c:if><c:if test="${pl.type=='03'}">合作社</c:if></td>
                                            <td class="center"><c:if test="${pl.state=='00'}"><span class="label label-important arrowed-in">未读</span></c:if><c:if test="${pl.state=='01'}"><span class="label label-success arrowed">已读</span></c:if></td>
											<td class="center">
                                               <a href="javascript:;" class="btn btn-xs btn-success"
                                                 onclick="seeMsg('${pl.id}')"> 
                                                                                                                                          查看信息                                                                                   
                                               </a>
											</td>
										</tr>
									
									</c:forEach>
									<%-- </c:if> --%>
									<c:if test="${QX.cha == 0 }">
										<tr>
											<td colspan="10" class="center">您无权查看</td>
										</tr>
									</c:if>
								</c:when>
								<c:otherwise>
									<tr class="main_info">	
										<td colspan="15" class="center">没有相关数据</td>
									</tr>
								</c:otherwise>
							</c:choose>
							</tbody>
						</table>
						
					<div class="page-header position-relative">
					<table style="width:100%;">
						<tr>
								<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
							</tr>
					</table>
					</div>
					</form>
	
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->

		<!-- 返回顶部 -->
		<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
			<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
		</a>

	</div>
	<!-- /.main-container -->

	<!-- basic scripts -->
	<!-- 页面底部js¨ -->
	<%@ include file="../index/foot.jsp"%>
	<!-- 删除时确认窗口 -->
	<script src="static/ace/js/bootbox.js"></script>
	<!-- ace scripts -->
	<script src="static/ace/js/ace/ace.js"></script>
	<!-- 日期框 -->
	<script src="static/ace/js/date-time/bootstrap-datepicker.js"></script>
	<!-- 下拉框 -->
	<script src="static/ace/js/chosen.jquery.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	</body>

<script type="text/javascript">
$(top.hangge());
//检索
function searchs(){
	top.jzts();
	$("#goodsForm").submit();
}
//对接
function seeMsg(id){
	 top.jzts();
	 var diag = new top.Dialog();
	 diag.Drag=true;
	 diag.Title ="加盟信息";
	 diag.URL = '<%=basePath%>fruitUser/seeMsg.do?id='+id;
	 diag.Width = 900;
	 diag.Height = 480;
	 diag.CancelEvent = function(){ //关闭事件
		 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
			nextPage('${page.currentPage}');
		}
		diag.close();
	 };
	 diag.show();	
}



//排序编辑
 
//检查是否为正整数
function isInt(a)
{
    var reg = /^\d+$/; 
    return reg.test(a);
}

function toGoodsSpec(goodId){
	 top.jzts();
	 var diag = new top.Dialog();
	 diag.Drag=true;
	 diag.Title ="设置规格";
	 diag.URL = '<%=basePath%>goods/goodsSpecList.do?goodsId='+goodId;
	 diag.Width = 1600;
	 diag.Height = 700;
	 diag.CancelEvent = function(){ //关闭事件
		 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
			nextPage('${page.currentPage}');
		}
		diag.close();
	 };
	 diag.show();
}

		
function toGoodsUnit(goodsId){
	 top.jzts();
	 var diag = new top.Dialog();
	 diag.Drag=true;
	 diag.Title ="设置商品发货地";
	 diag.URL = '<%=basePath%>goods/goodsUnitList.do?goodsId='+goodsId;
	 diag.Width = 700;
	 diag.Height = 300;
	 diag.CancelEvent = function(){ //关闭事件
		 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
			nextPage('${page.currentPage}');
		}
		diag.close();
	 };
	 diag.show();
}

function toGoodsPrice(goodsId){
	 top.jzts();
	 var diag = new top.Dialog();
	 diag.Drag=true;
	 diag.Title ="设置批发价区间";
	 diag.URL = '<%=basePath%>goods/goodsPriceList.do?goodsId='+goodsId;
	 diag.Width = 800;
	 diag.Height = 400;
	 diag.CancelEvent = function(){ //关闭事件
		 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
			nextPage('${page.currentPage}');
		}
		diag.close();
	 };
	 diag.show();
}
//复选框全选控制
var active_class = 'active';
$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
	var th_checked = this.checked;//checkbox inside "TH" table header
	$(this).closest('table').find('tbody > tr').each(function(){
		var row = this;
		if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
		else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
	});
});
//批量上架
function batchUpState(){
			var str='';
			var state='';
			for(var i=0;i < document.getElementsByName('ids').length;i++)
			{
				  if(document.getElementsByName('ids')[i].checked){
					  if(document.getElementsByName('ids')[i].id !='00'){
							alert("存在已上架期次");
							return false;
						}
				  	if(str==''){
				  		str += document.getElementsByName('ids')[i].value;
				  	}else {
				  		str += ',' + document.getElementsByName('ids')[i].value;
				  	}
				  }
			} 
		 	if(str==''){
				alert("您没有选择任何商品");
				return false;
			}else{ 
					$.ajax({
						type: "POST",
						url: '<%=basePath%>period/updateBatchState.do?tm='+new Date().getTime(),
				    	data: {state:'01',ids:str},
						success: function(data){
						    if("success"==data){
							  alert("批量上架成功");
						   }else if("timeEnd"==data.substring(0,7)){
							   alert("id为(  "+data.substring(7,data.length)+"  )的期次下架时间已到，无法上架");
						   }else if("no-spec"==data.substring(0,7)){
							   alert("id为(  "+data.substring(7,data.length)+"  )的期次未找到商品，无法上架");
						   }else if("userTimeEnd"==data.substring(0,11)){
							   alert("id为(  "+data.substring(11,data.length)+"  )的期次截止使用时间已到，无法上架");
						   }else if("no-stock"==data.substring(0,8)){
							   alert("id为(  "+data.substring(8,data.length)+"  )的期次库存到达上限，无法上架");
						   }else if("no-state"==data.substring(0,8)){
							   alert("id为(  "+data.substring(8,data.length)+"  )的期次区域商品未上架，无法上架");
						   }else if("no-goods"==data.substring(0,8)){
							   alert("id为(  "+data.substring(8,data.length)+"  )的期次还未绑定区域商品，无法上架");
						   }else{
							   alert("批量上架失败");
						   }
							nextPage('${page.currentPage}');
						}
					});
				}
		}

//导出excel
function toExcel(){
	var keywords = $("#keywords").val();
	var code = $("#code").val();
	var state = $("#state").val();
	var stockState = $("#stockState").val();
	var startDiscount = $("#startDiscount").val();
	var endDiscount = $("#endDiscount").val();
	window.location.href='<%=basePath%>goods/excel.do?keywords='+keywords+'&code='+code+'&state='+state+'&stockState='+stockState+'&startDiscount='+startDiscount+'&endDiscount='+endDiscount;
}

//批量下架
function batchDownState(){
	var str='';
	var state='';
	for(var i=0;i < document.getElementsByName('ids').length;i++)
	{
		  if(document.getElementsByName('ids')[i].checked){
			  if(document.getElementsByName('ids')[i].id!='01'){
					alert("存在已下架期次");
					return false;
				}
		  	if(str=='') str += document.getElementsByName('ids')[i].value;
		  	else str += ',' + document.getElementsByName('ids')[i].value;
		  }
	} 
 	if(str==''){
		alert("您没有选择任何商品");
		return false;
	}else{ 
			$.ajax({
				type: "POST",
				url: '<%=basePath%>period/updateBatchState.do?tm='+new Date().getTime(),
		    	data: {state:'00',ids:str},
				success: function(data){
					if("success" == data){
						 alert("批量下架成功");
					}else{
						 alert("批量下架失败");
					}
					nextPage('${page.currentPage}');
					 
				}
			});
		}
}
//删除
function delgood(id){
	bootbox.confirm("确定要删除吗?", function(result) {
		if(result) {
			top.jzts();
			var url = "<%=basePath%>goods/delGood.do?id="+id;
			$.get(url,function(data){
				if(data=="success"){
					alert("删除成功");
				}
				else{
					alert("删除失败");
				}
				nextPage('${page.currentPage}');
			});
		};
	});
}
//批量删除
function delGoods(){
			var str='';
			var state='';
			for(var i=0;i < document.getElementsByName('ids').length;i++)
			{
				  if(document.getElementsByName('ids')[i].checked){
					  if(document.getElementsByName('ids')[i].id!='00'){
							alert("存在已上架商品,请先下架再删除");
							return false;
						}
				  	if(str=='') str += document.getElementsByName('ids')[i].value;
				  	else str += ',' + document.getElementsByName('ids')[i].value;
				  }
			} 
		 	if(str==''){
				alert("您没有选择任何商品");
				return false;
			}else{ 
					$.ajax({
						type: "POST",
						url: '<%=basePath%>goods/delGoods.do?tm='+new Date().getTime(),
				    	data: {ids:str},
						success: function(data){
							if(data=="success"){
								alert("批量删除成功");
							}
							else{
								alert("批量删除失败");
							}
							nextPage('${page.currentPage}'); 
						}
					});
				}
		}

</script>
</html>
